package org.qy137.controller;

import com.qy137.vo.LinkVo;
import io.swagger.annotations.ApiOperation;
import org.qy137.service.LinkService;
import org.qy137.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"link"})
public class LinkController {
    @Autowired
    private LinkService linkService;

    public LinkController() {
    }

    @ApiOperation("分页查询友情链接")
    @GetMapping({"getAllLink/{page}/{limit}"})
    public CommonResult getAllLink(@PathVariable Integer page, @PathVariable Integer limit, @RequestBody(required = false) LinkVo linkVo) {
        return this.linkService.getAllLink(page, limit, linkVo);
    }

    @ApiOperation("修改友情链接的状态")
    @PutMapping({"changeStatus/{linkId}/{isDisable}"})
    public CommonResult changeStatus(@PathVariable String linkId, @PathVariable Integer isDisable) {
        return this.linkService.changeStatus(linkId, isDisable);
    }

    @DeleteMapping({"deleteLink/{linkId}"})
    @ApiOperation("逻辑删除友情链接")
    public CommonResult deleteLink(@PathVariable String linkId) {
        return this.linkService.deleteLink(linkId);
    }

    @ApiOperation("新增或修改友情链接")
    @PostMapping({"updateOrAddLink"})
    public CommonResult updateOrAddLink(@RequestBody LinkVo linkVo) {
        return this.linkService.updateOrAddLink(linkVo);
    }
}
